package com.clstu.enum_;

public class EnumMethod {
    public static void main(String[] args) {
        Season02 ss=Season02.SUMMER;
        System.out.println(ss.name());//输出枚举对象的常量变量名
        System.out.println(ss.ordinal());//输出该对象在枚举对象数组中的下标
        Season02[] sss=Season02.values();//返回枚举类型的枚举对象数组
        for(Season02 season:sss){
            System.out.println(season.name());
        }
        System.out.println(Season02.valueOf("SUMMER"));//valueOf()通过常量名找到对应的枚举对象
        System.out.println(ss.compareTo(Season02.SUMMER));//返回这两个枚举对象在枚举对象数组中下标的差值


    }
}
enum Season02{//将class改为enum，2.直接名称+构造器参数

    //底层的机制还是考publi static final Season SUMMER ... 来实现的，
    // 底层的类都默认继承了Enum类，可以通过Javap反编译工具反编译Season01.class文件查看，

    SPRING("春季","温暖"),SUMMER("夏季","炎热"),AUTUMN("秋天","凉爽"),
    WINTER("冬天","寒冷"),HAHA;//当调用无参构造器的时候甚至可以不加括号（）
    private String name01;
    private String desc;

    private Season02(){

    }

    private Season02(String name, String desc) {
        this.name01 = name;
        this.desc = desc;
    }

    public String getName() {
        return name01;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return "Season{" +
                "name='" + name()+ '\'' +
                ", desc='" + desc + '\'' +
                '}';
    }
}